package com.futures.investm.adapter;

import android.view.View;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.futures.investm.R;
import com.futures.investm.entity.MarketInfo;
import com.futures.investm.utils.IntentUtils;

import java.util.ArrayList;


/**
 * 贵金属行情
 */
public class MarketMetalAdapter extends BaseQuickAdapter<MarketInfo, BaseViewHolder> {

    public MarketMetalAdapter() {
        super(R.layout.item_oil_market, new ArrayList<MarketInfo>());
    }

    @Override
    protected void convert(BaseViewHolder helper, final MarketInfo item) {
        Double f1 = Double.parseDouble(item.getLast());
        Double f2 = Double.parseDouble(item.getPrev());

        Double dPC = Double.parseDouble(item.getPricechange()) * 100;

        helper.setText(R.id.tv_name,item.getName());
        helper.setText(R.id.tv_price,item.getLast());
        helper.setText(R.id.tv_percent,String.format("%.2f", dPC) + "%");



        if (Float.parseFloat(item.getPricechange()) > 0) {
            helper.setTextColor(R.id.tv_price,mContext.getResources().getColor(R.color.market_red) );
            helper.setTextColor(R.id.tv_percent, mContext.getResources().getColor(R.color.market_red));
//            helper.setImageDrawable(R.id.img_line,mContext.getResources().getDrawable(R.mipmap.red));
        } else {
            helper.setTextColor(R.id.tv_price, mContext.getResources().getColor(R.color.market_blue));
            helper.setTextColor(R.id.tv_percent,mContext.getResources().getColor(R.color.market_blue));
//            helper.setImageDrawable(R.id.img_line,mContext.getResources().getDrawable(R.mipmap.blue));
        }

        String symbol = item.getSymbol();
        String strK = "";
        if (symbol.equals("SI")) {//COMEX白银
            strK = "COMEXSI";
        } else if (symbol.equals("XAG")) {//伦敦银
            strK = "";
        } else if (symbol.equals("XAU")) {//伦敦金
            strK = "";
        } else if (symbol.equals("XPD")) {//伦敦钯金
            strK = "";
        } else if (symbol.equals("XPT")) {//伦敦铂金
            strK = "";
        }
        final String finalStrK = strK;

        helper.itemView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                IntentUtils.goMarketDetailsActivity(mContext, finalStrK, item.getName(), "1", item.getSymbol());
            }
        });

    }
}
